﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADDDF.Infrastructure.DomainBase;
using System.Collections.ObjectModel;

namespace ADDDF.Infrastructure.ChangeTracking.ChangeRecords
{
    class EntityRecord
    {
        private Type _type;
        private object _key;
        private IEntity _value;
        private Dictionary<IChangeRule, RuleRecord> _ruleRecords;

        public EntityRecord(Type type, object key, IEntity value)
        {
            _type = type;
            _key = key;
            _value = value;
            _ruleRecords = new Dictionary<IChangeRule, RuleRecord>(new ChangeRuleEqualityComparer());
        }

        public Type Type
        {
            get { return _type; }
        }

        public object Key
        {
            get { return _key; }
        }

        public IEntity Value
        {
            get { return _value; }
        }

        public bool IsChanged
        {
            get;
            set;
        }

        public void AddRuleRecord(RuleRecord ruleRecord)
        {
            if(!_ruleRecords.ContainsKey(ruleRecord.Rule))
                _ruleRecords.Add(ruleRecord.Rule, ruleRecord);
        }

        public ReadOnlyCollection<RuleRecord> RuleRecords
        {
            get { return new ReadOnlyCollection<RuleRecord>(_ruleRecords.Values.ToList()); }
        }
        
    }
}
